package com.patrol.patrol.ui.appear;


import com.patrol.patrol.ui.BaseFragment;

import java.util.HashMap;
import java.util.Map;

public class FragmentFactory {

    /**
     * 信息
     */
    public static final int TAB_RECOMMEND = 0;
    /**
     * 记录
     */
    public static final int TAB_CATEGORY = 1;

    private static Map<Integer, BaseFragment> mFragmentMap = new HashMap<>();

    public static BaseFragment createFragment(int index){
        BaseFragment fragment = mFragmentMap.get(index);
        //如果之前没有创建，就创建新的
        if (fragment == null){
            switch (index){
                case TAB_RECOMMEND:
                    fragment = new AppearFragment();
                    break;
                case TAB_CATEGORY:
                    fragment = new ListFragment();
                    break;
            }
            //把创建的fragment存起来
            mFragmentMap.put(index,fragment);
        }
        return fragment;
    }
}